package com.mapTest;


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

/**
 * @Author weijingchen
 * @Date 2025/6/13 21:27
 * @Version 1.0.0
 */
public class Test {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("1", "1");
        map.put("2", "2");
        map.put("3", "3");
        map.put("4", "4");

        //通过健找值
        Set<String> keySet = map.keySet();
        for (String key : keySet){
            System.out.println(key+":"+map.get(key));
        }

        System.out.println("----------------------------------------------------------------");
        //通过键值对
        Set<Map.Entry<String, String>> entrySet = map.entrySet();
        for (Map.Entry<String, String> entry : entrySet){
            System.out.println(entry.getKey()+":"+entry.getValue());
        }

        Iterator<Map.Entry<String, String>> iterator = entrySet.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> next = iterator.next();
            System.out.println(next.getKey()+":"+next.getValue());
        }

        entrySet.forEach(e-> System.out.println(e.getKey()+":"+e.getValue()));

        System.out.println("----------------------------------------------------------------");
        //lambda表达式
        map.forEach((k,v)-> System.out.println(k+":"+v));
        map.forEach((s, s2) -> System.out.println(s+":"+s2));
    }
}
